﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Recursos.Model;

namespace Recursos.Account
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            
            var permisos = new PermisosModel();
            var usuario = permisos.VerificarUsuario(LoginUser.UserName, LoginUser.Password);
            var isMember = usuario.Any() && usuario.First().contraseña.Equals(LoginUser.Password);

            if (isMember)
            {
                FormsAuthentication.RedirectFromLoginPage(LoginUser.UserName,
                LoginUser.RememberMeSet);
                Session["UserLogged"] = usuario.First();
                Page.Response.Redirect("~/Default.aspx");

            }
            else
            {
                Page.Response.Redirect("~/Account/Login.aspx");
                
            }
        }
    }
}
